#include <iostream>
#include <algorithm>
using namespace std;
int N,cnt=0, maxnum = -1;
int bucket[100005] = {0};
int used[100005] = {0};

int mins(int k)
{
    int tmp = k;
    for(int i = 1;i <= maxnum;i++)
    {
        if(bucket[i]) tmp--;
        if(tmp == 0) return i;
    }
    return -1;
}

int out()
{
    int cnt = 0;
    for(int i = 1;i <= maxnum;i++)
    {
        if(bucket[i])
           cnt += bucket[i];
    }
    return cnt;
}

int main()
{
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);

    cin >> N;
    for(int i = 1;i <= N;i++)
    {
        int k;
        cin >> k;
        maxnum = max(maxnum,k);
        bucket[k] ++;
    }
    while(bucket[maxnum] != used[maxnum])
    {
        int m1 = mins(1), m2 = mins(2);
        if(m2 == -1 || m1 == -1) break;
        int r = min(bucket[m1],bucket[m2] - used[m2]);
        cnt += r*2;
        bucket[m1] -= r;
        used[m2] += r;
    }
    cout << out();

    fclose(stdin);
    fclose(stdout);
    return 0;
}
